package com.zhss.demo.register.server;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 完整的服务实例信息
 * @author: zcl
 * @date: 2021/1/13 20:37
 * @description:
 */
public class Applications {
    Map<String, Map<String, ServiceInstance>> register=new HashMap<String, Map<String, ServiceInstance>>();

    public Applications() {
    }

    public Applications(Map<String, Map<String, ServiceInstance>> register) {
        this.register = register;
    }

    public Map<String, Map<String, ServiceInstance>> getRegister() {
        return register;
    }

    public void setRegister(Map<String, Map<String, ServiceInstance>> register) {
        this.register = register;
    }

    @Override
    public String toString() {
        return "Applications{" +
                "register=" + register +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Applications applications = new Applications();
        Map<String, Map<String, ServiceInstance>> tempRegister=new HashMap<String, Map<String, ServiceInstance>>();
        register.keySet();
        for (String serviceName : register.keySet()) {
            Map<String, ServiceInstance> serviceInstanceMap = register.get(serviceName);
            Map<String, ServiceInstance> tempMap=new HashMap<String, ServiceInstance>();
            for (String serviceId : serviceInstanceMap.keySet()) {
                ServiceInstance serviceInstance = serviceInstanceMap.get(serviceId);
                ServiceInstance tempServiceInstance=null;
                if(serviceId!=null){
                    tempServiceInstance= (ServiceInstance) serviceInstance.clone();
                }
                tempMap.put(new String(serviceId),tempServiceInstance);
            }
            tempRegister.put(new String(serviceName),tempMap);
        }
        applications.setRegister(tempRegister);
        return applications;
    }
}
